/*
 * @Description: 日志管理reducer
 * @Author: Rfan
 * @Date: 2022-09-19 14:08:51
 * @LastEditTime: 2022-09-19 17:47:51
 */

import {
  SET_SELECTED_ITEM,
  SET_CURRENT_PAGE,
  SET_ARCHIVE_DATA,
  PAGE_TYPE_RESULT
} from '../constants';

export const OnlinePreviewReducer = (state, action) => {
  switch (action.type) {
    /**
     * @description: 设置选中的日志单类型
     */
    case SET_CURRENT_PAGE:
      return {
        ...state,
        currentPage: action.data
      };

    /**
     * @description: 保存表格选中的条目id
     * @param {number[]} data
     */
    case SET_SELECTED_ITEM:
      return { ...state, selectItems: action.data };

    /**
     * @description: 设置日志单列表
     * @param {Array} data 日志单列表
     */
    case SET_ARCHIVE_DATA: {
      return {
        ...state,
        archiveData: action.data,
        currentPage: PAGE_TYPE_RESULT
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
